package com.hmall.search.service.impl;


import com.hmall.common.dto.FiltersDTO;
import com.hmall.common.dto.FiltersVO;
import com.hmall.common.dto.Item;
import com.hmall.common.dto.PageDTO;
import com.hmall.fegin.clients.ItemClient;
import com.hmall.search.service.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.Collections;
import java.util.List;

/**
 * TODO
 *
 * @Author anjing
 * @Date 2024/11/15 10:45
 */
@Service
public class SearchServiceImpl implements SearchService {

    @Autowired
    private ItemClient itemClient;
    @Autowired
    private  StringRedisTemplate stringRedisTemplate;
    @Override
    public FiltersVO filterss(FiltersDTO filtersDTO) {

        if(StringUtils.isEmpty(filtersDTO.getCategory())){
            List<String> brand = itemClient.getBrandList();
            List<String> category = itemClient.getlist();
            return FiltersVO.builder().brand(brand)
                    .category(category).build();

        }
        FiltersVO filter = itemClient.getFilter(filtersDTO.getCategory());
        filter.setCategory(Collections.singletonList(filtersDTO.getCategory()));
        return filter;
    }

    @Override
    public PageDTO<Item> list1(FiltersDTO filtersDTO) {


        PageDTO<Item> list = itemClient.list1(filtersDTO);

        return list;
    }

}
